package com.lxl;

import java.util.Random;
import java.util.Scanner;

//猜数字游戏
public class GuessNumber {
    public static void main(String[] args) {

        /*System.out.println("随机数已生成!");
        int f = new Random().nextInt(10);
        System.out.println(f);
        System.out.println("请输入您猜的数字");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        if (i > f) {
            System.out.println("sorry,您猜大了!");
        } else if (i < f) {
            System.out.println("sorry,您猜小了!");
        } else {
            System.out.println("恭喜您,答对了!");
        }*/
        System.out.println("随机数已生成!");
        Random random = new Random();
        int f = random.nextInt(10);
        System.out.println(f);
        System.out.println("请输入您猜的数字");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        while (i != f) {
            if (i > f) {
                System.out.println("sorry,您猜大了!");
                System.out.println("请重新输入");
            } else {
                System.out.println("sorry,您猜小了!");
                System.out.println("请重新输入");
            }
            i = scanner.nextInt();
        }
        System.out.println("恭喜您,答对了!");



        /*System.out.println("sorry,您猜小了!");
        System.out.println("sorry,您猜大了!");
        System.out.println("恭喜您,答对了!");*/
    }
}
